<template>
  <div class='home'>
    <!-- 推荐歌单 -->
    <div>
      <!-- 标题 -->
      <div class="title">推荐歌单</div>
      <!-- 每个歌单item -->
      <div class="song-item">
        <van-row gutter="8">
          <van-col v-for="item in recommendList" :key="item.id" span="8">
            <van-image
              width="100%"
              height="100"
              fit="cover"
              :src="item.picUrl"
            />
            <div class="song_name">{{ item.name }}</div>
          </van-col>
        </van-row>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div>
      <!-- 标题 -->
      <div class="title">最新音乐</div>
      <van-cell-group>
        <!-- 使用全局组件 -->
        <MusicCell
          v-for="(item, index) in newSongList"
          :id="item.id"
          :key="index"
          :title="item.name"
          :label="`${item.song.artists[0].name} - ${item.name}`"
        ></MusicCell>
      </van-cell-group>
    </div>
  </div>
</template>

<script>
// 导入封装的请求函数
import { recommendAPI, newSongAPI } from "@/api/home.js";
export default {
  data() {
    return {
      recommendList: [],
      newSongList: [],
    };
  },
  async created() {
    const res = await recommendAPI({ limit: 6 });
    this.recommendList = res.data.result;
    // console.log(this.recommendList);
    const res2 = await newSongAPI();
    // console.log(res2);
    this.newSongList = res2.data.result;
    // console.log(this.newSongList);
  },
};
</script>

<style scoped>
/* 标题 */
.title {
  padding: 10px 15px;
  margin: 0 0 15px 0;
  background-color: #eee;
  color: #333;
  font-size: 15px;
}
/* 推荐歌单 - 歌名 */
.song_name {
  font-size: 14px;
  padding: 0 5px;
  margin-bottom: 10px;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2; /** 显示的行数 **/
  overflow: hidden; /** 隐藏超出的内容 **/
}
</style>